﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Windows;

namespace CI.Utility
{
    public class DragDropAdornerConverter : IValueConverter
    {
        private static ResourceDictionary _adorners;

        static DragDropAdornerConverter()
        {
            _adorners = new ResourceDictionary();

            _adorners.Source =
                new Uri("/CI;component/Views/DragDropAdornerDataTemplates.xaml",
                    UriKind.RelativeOrAbsolute);
        }

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null) return null;
            //TODO:Load the data template from resources based on the type of the vaue + "DragtDropAdorner"
            var t = value.GetType().Name;
            try
            {
                var r = _adorners[value.GetType().Name + "DragDropAdorner"] as DataTemplate;
                return r;
            }
            catch (Exception)
            {
                return null;
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
